#include <stdio.h>
#include <SFML/System.hpp>
#include <SFML/Graphics.hpp>

#include "debug.hpp"
#include "animation_view.hpp"

int main(int argc, char **argv)
{
	try
	{
	sf::Clock timer;
	
	AnimationView anim_view;
	anim_view.Initialize(argc, const_cast<const char**>(argv));	
	
	sf::VideoMode mode = sf::VideoMode::GetDesktopMode();
	mode.Width = anim_view.GetWidht();
	mode.Height = anim_view.GetHeight();
	sf::RenderWindow window(mode, "anim view");
	
	while (window.IsOpened())
	{
		sf::Event event;
		while (window.GetEvent(event))
		{
			switch (event.Type)
			{
				case sf::Event::Closed:
					window.Close();
					break;
				case sf::Event::KeyReleased:
					if (event.Key.Code == sf::Key::F5)
					{
						anim_view.Initialize(argc, const_cast<const char**>(argv));
					}
					break;
				default:
					break;
			}
		}
		float dt = timer.GetElapsedTime();
		timer.Reset();
		anim_view.Update(dt);
		window.Clear(sf::Color(0, 0, 0));
		anim_view.Render(window);
		window.Display();
		//sf::Sleep(1.0f);
	}
	} catch (const std::runtime_error& err)
	{
		debug_message_box("error", err.what());
	}
	return EXIT_SUCCESS;
}
